package cn.maxwell.controller;

import cn.maxwell.domain.Product;
import cn.maxwell.mapper.ProductMapper;
import cn.maxwell.server.IProductServers;
import cn.maxwell.util.JsonResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Resource
    private IProductServers productServers;

    @Value("${server.port}")
    private Integer port;

    @GetMapping("/loadById/{id}")
    public Product loadById(@PathVariable("id") Long id){
        Product product = productServers.loadById(id);
        return product;
    }

    @PostMapping("/add")
    public JsonResult add(@RequestBody Product product){
        try {
            productServers.add(product);
            return new JsonResult(true,"操作成功！");
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonResult(false,"操作失败！");
        }
    }
}
